<?php 
namespace frontend\controllers;
use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\UploadedFile;
use yii\web\Controller;
use frontend\models\ComponyMsg;
use frontend\models\Resume;
use frontend\models\UploadForm;
use frontend\models\PositionType;
class ComponyController extends controller
{
	public $layout='index2';

	//关闭这个可以使用原生form
	public $enableCsrfValidation = false;
	public function init()
	{
		parent::init();
		session_start();
	}

	public function actionIndex()
	{
		$ar=new ComponyMsg();
		$model=new UploadForm();

		//这边需要根据session获取id
		$id = $_SESSION['user']['user_id'];

		$arr=ComponyMsg::find()->where("user_id=$id")->one();
		if ($arr) {
			   $this->redirect('?r=compony2/data');
		}else{
			if ($model->load($data=Yii::$app->request->post())) {
				$model->logo=UploadedFile::getInstance($model,'logo');
				$img=$model->getname();
				if (file_exists($img)) {
					$file=$img;
				}else{
					$file=$model->upload();
				}
				$ar->logo=$file;
				$ar->status=2;
				$ar->compony_name=$model->compony_name;
				$ar->compony_area=$model->compony_area;
				$ar->content=$model->content;
				$ar->name=$model->name;
				$ar->tel=$model->tel;
				$ar->user_id=$id;
				$ar->insert();
				$this->redirect('?r=compony2/data');
			}else{
		          return $this->render('index',['model'=>$model]);	   
			}
		}
	}
	public function actionPerson()
	{
		      $user_id=Yii::$app->request->get('user_id');
		      $arr=Resume::find()->where("user_id=$user_id")->one();
		      return $this->render('person',['data'=>$arr]);
	}
	
}

 ?>